unit UFrmclientes;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ToolEdit, RXDBCtrl, StdCtrls, Mask, DBCtrls, Buttons, ExtCtrls, RXCtrls,
  Grids, Wwdbigrd, Wwdbgrid, ComCtrls;

type
  TFrmClientes = class(TForm)
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    DBEdit1: TDBEdit;
    DBEdit4: TDBEdit;
    DBEdit5: TDBEdit;
    DBEdit6: TDBEdit;
    DBDateEdit1: TDBDateEdit;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Label7: TLabel;
    Label9: TLabel;
    DBEdit2: TDBEdit;
    GroupBox3: TGroupBox;
    Label10: TLabel;
    Label12: TLabel;
    Label11: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    DBEdit3: TDBEdit;
    DBEdit10: TDBEdit;
    DBEdit9: TDBEdit;
    DBEdit11: TDBEdit;
    DBEdit13: TDBEdit;
    DBComboBox1: TDBComboBox;
    GroupBox4: TGroupBox;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    DBEdit12: TDBEdit;
    DBEdit14: TDBEdit;
    DBEdit15: TDBEdit;
    DBEdit16: TDBEdit;
    DBEdit17: TDBEdit;
    DBEdit18: TDBEdit;
    Panel2: TPanel;
    Label22: TLabel;
    Label23: TLabel;
    Panel3: TPanel;
    Label24: TLabel;
    Image1: TImage;
    Edit1: TEdit;
    RxLabel1: TRxLabel;
    Panel4: TPanel;
    btnPrimeiro: TSpeedButton;
    btnAnterior: TSpeedButton;
    Bevel1: TBevel;
    DBEdit8: TDBEdit;
    btnProximo: TSpeedButton;
    btnUltimo: TSpeedButton;
    btnGravar: TSpeedButton;
    btnExcluir: TSpeedButton;
    SpeedButton1: TSpeedButton;
    btnAdicionar: TSpeedButton;
    SpeedButton2: TSpeedButton;
    btnRetornar: TSpeedButton;
    Label8: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    Label38: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label41: TLabel;
    Label42: TLabel;
    Label43: TLabel;
    DBLookupComboBox1: TDBLookupComboBox;
    DBText1: TDBText;
    Label44: TLabel;
    wwDBGrid1: TwwDBGrid;
    StatusBar1: TStatusBar;
    procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Label23MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure btnRetornarClick(Sender: TObject);
    procedure btnPrimeiroClick(Sender: TObject);
    procedure btnAnteriorClick(Sender: TObject);
    procedure btnProximoClick(Sender: TObject);
    procedure btnUltimoClick(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure btnExcluirClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure btnAdicionarClick(Sender: TObject);
    procedure Label25MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label26MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label27MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label28MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label29MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure GroupBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label30MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label31MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure GroupBox2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label32MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label35MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label33MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label34MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label36MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label37MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label38MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label43MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label39MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label42MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label40MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Label41MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure GroupBox4MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure GroupBox3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure wwDBGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure DBEdit12Exit(Sender: TObject);
    procedure DBEdit14Exit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmClientes: TFrmClientes;

implementation

uses Modulo, UFrmNiver;

{$R *.DFM}

procedure TFrmClientes.Panel1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
   Label22.Visible := false;
end;

procedure TFrmClientes.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   Action := CaFree;
end;

procedure TFrmClientes.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
   if MessageDlg('        Deseja realmente encerrar'+#13+'Cadastro de informações de Clientes?',MtConfirmation,[mbyes, mbno],0) = mrno then
      Canclose := false;
end;

procedure TFrmClientes.Label23MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   Label22.Visible := true;
end;

procedure TFrmClientes.btnRetornarClick(Sender: TObject);
begin
   close;
end;

procedure TFrmClientes.btnPrimeiroClick(Sender: TObject);
begin
   DMEscola.Qclientes.First;
end;

procedure TFrmClientes.btnAnteriorClick(Sender: TObject);
begin
   DMEscola.Qclientes.Prior;
   if (DMEscola.Qclientes.Bof) then
      DMEscola.Qclientes.First;
end;

procedure TFrmClientes.btnProximoClick(Sender: TObject);
begin
   DMEscola.Qclientes.Next;
   if (DMEscola.Qclientes.EOF) then
      DMEscola.Qclientes.Last;
end;

procedure TFrmClientes.btnUltimoClick(Sender: TObject);
begin
   DMEscola.Qclientes.Last;
end;

procedure TFrmClientes.btnGravarClick(Sender: TObject);
begin
   DMEscola.Qclientes.Edit;
   DMEscola.Qclientes.Post;
   ShowMessage('Cliente Gravado com sucesso!');
   DMEscola.Qclientes.Edit;
end;

procedure TFrmClientes.btnExcluirClick(Sender: TObject);
begin
   if MessageDLg('Tem certeza que deseja excluir o registro?',mtConfirmation,[mbyes, mbno],0) = mryes then
      DMEscola.Qclientes.Delete;
end;

procedure TFrmClientes.SpeedButton1Click(Sender: TObject);
begin
   DMEscola.Qclientes.Edit;
end;

procedure TFrmClientes.btnAdicionarClick(Sender: TObject);
begin
   DMEscola.Qclientes.Append;
end;

procedure TFrmClientes.Label25MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   Label1.Visible := True;
end;

procedure TFrmClientes.Label26MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   Label5.Visible := true;
end;

procedure TFrmClientes.Label27MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   Label3.Visible := true;
end;

procedure TFrmClientes.Label28MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   Label6.Visible := true;
end;

procedure TFrmClientes.Label29MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label4.visible := true;
end;

procedure TFrmClientes.GroupBox1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label1.visible := false;
   label2.visible := false;
   label3.visible := false;
   label4.visible := false;
   label5.visible := false;
   label6.visible := false;
end;

procedure TFrmClientes.Label30MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label2.visible := true;
end;

procedure TFrmClientes.Label31MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label7.visible := true;
end;

procedure TFrmClientes.GroupBox2MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label2.visible := false;
   label7.visible := false;
end;

procedure TFrmClientes.Label32MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label10.visible := true;
end;

procedure TFrmClientes.Label35MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label12.Visible := true;
end;

procedure TFrmClientes.Label33MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label13.visible := true;
end;

procedure TFrmClientes.Label34MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label11.visible := true;
end;

procedure TFrmClientes.Label36MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label14.visible := true;
end;

procedure TFrmClientes.Label37MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label15.visible := true;
end;

procedure TFrmClientes.Label38MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label16.visible := true;
end;

procedure TFrmClientes.Label43MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label19.visible := true;
end;

procedure TFrmClientes.Label39MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label17.visible := true;
end;

procedure TFrmClientes.Label42MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label20.visible := true;
end;

procedure TFrmClientes.Label40MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label18.visible := true;
end;

procedure TFrmClientes.Label41MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label21.visible := true;
end;

procedure TFrmClientes.GroupBox4MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label16.visible := false;
   label17.visible := false;
   label18.visible := false;
   label19.visible := false;
   label20.visible := false;
   label21.visible := false;
end;

procedure TFrmClientes.GroupBox3MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   label10.visible := false;
   label11.visible := false;
   label12.visible := false;
   label13.visible := false;
   label14.visible := false;
   label15.visible := false;
end;

procedure TFrmClientes.SpeedButton2Click(Sender: TObject);
begin
   Rxlabel1.Visible := true;
   edit1.Visible := true;
   edit1.Text := '';
   Edit1.SetFocus;
   Label24.Caption := 'Modo de Consulta';
   Label24.Font.Color := $00D3440E;
end;

procedure TFrmClientes.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  var
    vBusca : String;
begin
  Case key of
    VK_Return:
     Begin
       if (Edit1.text = '') then
          begin
             ShowMessage('Digite um nome '+#13+
                      'para pesquisar!');
             Edit1.SetFocus;
             exit;
          end;
       if (Edit1.text <> '') then
          begin
              vBusca:='';
              DMEscola.QClientes.Close;
              DMEscola.QClientes.SQL.Clear;
              DMEscola.QClientes.Sql.Add ('Select * From Clientes');
              DMEscola.QClientes.Sql.Add('WHERE ');
              DMEscola.QClientes.Sql.Add('(Nome like :pNOME) or');
              DMEscola.QClientes.Sql.Add('(NickName like :pNICK)');
              DMEscola.QClientes.ParamByName('pNOME').AsString:='%'+Edit1.text+'%';
              DMEscola.QClientes.ParamByName('pNICK').AsString:='%'+Edit1.text+'%';
              DMEscola.QClientes.open;
              vBusca:=DMEscola.QClientesNome.Value;
              If vBusca <> '' then
               begin
                  wwDBGrid1.visible:=True;
                  wwDBGrid1.setfocus;
                  GroupBox3.Visible := false;
                  GroupBox4.Visible := false;
               end
               else
                  If MessageDlg('Cliente não encontrado'+#13+'Deseja cadastrar agora?',mtConfirmation, [mbyes, mbno],0) =mryes then
                  begin
                      DMEscola.QClientes.Append;
                      DBEdit1.text := Edit1.text;
                      Edit1.Visible := false;
                      RxLabel1.Visible := false;
                      DBDateEdit1.SetFocus;
                  end;

              end;
          end;
end;
end;

procedure TFrmClientes.wwDBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
Case Key of
   VK_Return:
    Begin
       wwDBGrid1.visible:=False;
       Edit1.visible := False;
       DBEdit1.setFocus;
       GroupBox3.Visible := true;
       GroupBox4.Visible := true;
       RxLabel1.visible := false;
       Label24.caption := '';
       Label24.caption := 'Modo de Inclusão e Edição';
    end;
  end;
end;

procedure TFrmClientes.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
   if Key = vk_F12 then
      close;
   if Key = vk_F11 then
      SpeedButton2.Click;
   if Key = vk_F10 then
      BtnAdicionar.Click;
   if Key = vk_F9 then
      SpeedButton1.Click;
   if Key = vk_F8 then
      BtnExcluir.Click;
   if Key = vk_F7 then
      BtnGravar.Click;
end;

procedure TFrmClientes.FormShow(Sender: TObject);
begin
   if cli <> '' then
   begin
      DMEscola.QClientes.Close;
      DMEscola.QClientes.SQL.Clear;
      DMEscola.QClientes.Sql.Add ('Select * From Clientes');
      DMEscola.QClientes.SQL.Add('Where nome = :cli');
      DMEscola.QClientes.ParamByName('cli').AsString := cli;
      DMEscola.QClientes.Open
   end
   else
   begin
      DMEscola.QClientes.Close;
      DMEscola.QClientes.SQL.Clear;
      DMEscola.QClientes.Sql.Add ('Select * From Clientes');
      DMEscola.QClientes.Open
   end;
end;

procedure TFrmClientes.DBEdit12Exit(Sender: TObject);
var
   i : integer;
begin
   i := Length(DBEdit12.Text);
   if i = 7 then
      DBEdit12.text := formatfloat('000-0000',StrToFloat(DBEdit12.text))
   else
      DBEdit12.text := formatfloat('0000-0000',StrToFloat(DBEdit12.text));
end;

procedure TFrmClientes.DBEdit14Exit(Sender: TObject);
var
   i : integer;
begin
   i := Length(DBEdit12.Text);
   if i = 7 then
      DBEdit14.text := formatfloat('000-0000',StrToFloat(DBEdit14.text))
   else
      DBEdit14.text := formatfloat('0000-0000',StrToFloat(DBEdit14.text));
end;

end.
